﻿
#include <glut.h>
#include "Vector.h";
#include "MathExtra.h";
#include <Math.h>;

float animationAngle = 0;
int c = 20;
int h = 10; 

void Update(){
//Insert your Update logic here

}

void Draw() {
	//Insert your Draw logic here
	glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_DEPTH_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_QUADS);
		Vector3 p1,p2,p3,p4;
		float section1 = MathExtra::TwoPi / c;
		float section2 = MathExtra::Pi / h;
		animationAngle += 0.01;
	for(int i = 0;i < c;++i)
	{
		for(int j = 0;j <= h;++j)
		{
			int i2 = (i+1)%c;
			int j2 = j+1;
			p1 = Vector3::SphereToCartesian((section1*i)+animationAngle,section2*j,1);
			p2 = Vector3::SphereToCartesian((section1*i2)+animationAngle,section2*j,1);
			p3 = Vector3::SphereToCartesian((section1*i2)+animationAngle,section2*j2,1);
			p4 = Vector3::SphereToCartesian((section1*i)+animationAngle,section2*j2,1);
			glColor3f(0.0, 0.0, 0.0);
			glVertex3f(p1.X, p1.Y, p1.Z);
			glColor3f(0.5, 0.5, 0.5);
			glVertex3f(p2.X, p2.Y, p2.Z);
			glColor3f(1.0, 1.0, 1.0);
			glVertex3f(p3.X, p3.Y, p3.Z);
			glColor3f(0.5, 0.5, 0.5);
			glVertex3f(p4.X, p4.Y, p4.Z);
		}
	}
	glEnd();
	glutSwapBuffers(); 
	glFinish();
	glutPostRedisplay();
}

void Initialize() {
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClearDepth(1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glOrtho(-2.0, 2.0, -2.0, 2.0, -1.0, 1.0);
}

int main(int iArgc, char** cppArgv) {
	glutInit(&iArgc, cppArgv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(600, 600);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("XoaX.net");
	Initialize();
	Update();// need to limit this some how?
	glutDisplayFunc(Draw);
	glutMainLoop();
	return 0;
}